Crate egui_dock

source ·
Expand description

egui_dock: docking support for egui

Credit goes to @lain-dono for implementing the actual library.

This fork aims to provide documentation and further development if necessary.

Usage

The library is centered around the Tree. It stores the layout of Nodes which contains tabs.

Tree is generic (Tree<Tab>) so you can use any data to represent a tab. You show the tabs using DockArea and specify how they are shown by implementing TabViewer.

use egui_dock::{NodeIndex, Tree};

struct MyTabs {
    tree: Tree<String>
}

impl MyTabs {
    pub fn new() -> Self {
        let tab1 = "tab1".to_string();
        let tab2 = "tab2".to_string();

        let mut tree = Tree::new(vec![tab1]);
        tree.split_left(NodeIndex::root(), 0.20, vec![tab2]);

        Self { tree }
    }

    fn ui(&mut self, ui: &mut egui::Ui) {
        let style = egui_dock::Style::from_egui(ui.style().as_ref());
        egui_dock::DockArea::new(&mut self.tree)
            .style(style)
            .show_inside(ui, &mut TabViewer {});
    }
}

struct TabViewer {}

impl egui_dock::TabViewer for TabViewer {
    type Tab = String;

    fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
        ui.label(format!("Content of {tab}"));
    }

    fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
        (&*tab).into()
    }
}

Re-exports

pub use egui;

Structs

Stores the layout and position of all its tabs
For use with crate::DockArea::show when using DynamicTree.
Wrapper around indices to the collection of nodes inside a Tree.
Specifies the look and feel of egui_dock.
TabBuilderDeprecated
Identifies a tab within a Node.
Binary tree representing the relationships between Nodes.

Enums

Represents an abstract node of a Tree.
Direction in which a new node is created relatively to the parent node at which the split occurs.
Left or right alignment for tab add button.

Traits

TabDeprecated
Dockable tab that can be used in crate::Trees.
How we view a tab when its in a Tree.

Type Definitions

DynamicTreeDeprecated
A type-def for when using Tab or TabBuilder.